package predictionEngine;

public class Bootstrap {
    Dataset inbag,outOfBag,dataset;
    
    public Bootstrap(Dataset dataset) {
        this.dataset=dataset;
    }
    
    public Dataset getBag(){
        if(inbag==null)
            createInbag(); 
        return inbag;
    }
    
    public Dataset getOutofBag(){
        if(outOfBag==null)
            createOutOfBag();
        return outOfBag;
    }
    
    private void createInbag(){
        inbag = new Dataset(dataset.size());
        inbag.attributes=dataset.getAttributes();
        
        while (inbag.size()<dataset.size()){
            inbag.addInstance(dataset.instances.get((int)(Math.random()*dataset.size())));
        }
    }

    private void createOutOfBag() {
        outOfBag = new Dataset((int)(dataset.size()*0.5));
        for(double[] instance:dataset.getInstances()){
            if(!inbag.getInstances().contains(instance))
                outOfBag.addInstance(instance);
        }        
    }
}
